<template>
	<view>
		<view style="width: 100%;height: 750rpx">
			<view class="company-bg" :style="[{backgroundImage:'url('+bg+')'}]" :class="!bg?'bgClass':''">
				<cu-custom :isBack="true" :isWhiteBack="true" style="background-color: transparent;">
					<block slot="content">
						<view class="custom-white-title"></view>
					</block>
				</cu-custom>
				<!-- 编辑 -->
				<view v-if="!bg" @click="ChooseImage($event)" class="text-center" style="padding-top:150rpx;">
					<image src="https://txr001.zthj.net/static/img/addIMg.png" class="img"></image>
					<view class="text">上传企业照片</view>
				</view>
				<view v-if="!bg"  @click="ChooseImage($event)" class="camera-content222">
					<image src="https://txr001.zthj.net/static/img/camera.png" class="img-48"></image>
				</view>
				<!-- 查看 -->
				<view v-if="bg" class="text-center" style="padding-top:150rpx;">
					<image :src="bg" class="img imgs"></image>
				</view>
				<view v-if="bg"  @click="ChooseImage($event)" class="camera-content222">
					<image src="https://txr001.zthj.net/static/img/camera.png" class="img-48"></image>
				</view>
			</view>
		</view>
		
		<view class="padding-32">
			<view v-if="!optionList.logo" class="company-p" @click="ChooseImage($event,'logo')">
				<image :src="logo?logo:'https://txr001.zthj.net/uploads/20231125/Frame%2013484.png'" class="img-132"></image>
			    <image src="https://txr001.zthj.net/static/img/camera.png" class="camera"></image>  
			</view>
			<view v-if="optionList.logo" class="company-p" @click="ChooseImage($event,'logo')">
				<image :src="optionList.logo?optionList.logo:'https://txr001.zthj.net/uploads/20231125/Frame%2013484.png'" class="img-132"></image>
				<image src="https://txr001.zthj.net/static/img/camera.png" class="camera"></image> 
			</view>
		    <view class="company-title">
				<!-- <input placeholder="请点击输入公司名全称" name="input"></input> -->
				<view>{{optionList.company}}</view>
			</view>
			<view class="company-desc">
				企业描述
			</view>
			<view class="">
				<textarea v-model="memo" class="textarea" placeholder="请输入企业描述"></textarea>
				<!-- <view v-if="optionList.memo" class="textarea">{{optionList.memo}}</view> -->
			</view>
			<view class="padding-top-28 flex align-center justify-center margin-top-48" v-if="memo">
				<!-- <view @click="saveInfo">
					<image src="../../static/img/save.png" class="img-32"></image>
					<text class="save-text">保存</text>
				</view> -->
				<!-- <view @click="cancleInfo">
					<image src="../../static/img/cancle.png" class="img-32 margin-left-48"></image>
					<text class="cancle-text">取消</text>
				</view> -->
				<view class="saveBtn" @click="saveInfo">提交</view>
			</view>	
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				bg:"",
				memo:"",
				logo:"",
				optionList:null
			}
		},
		onLoad(option){
			console.log('22222',option)
			if(option.company){
				this.optionList=option
				this.bg=option.setting
				this.memo=option.memo
			}
		},
		onShow() {
		},
		methods: {
			// 保存
			async saveInfo(){
				let params = {
					bg_image:this.bg,
					memo:this.memo,
					logo:this.logo?this.logo:this.optionList.logo
				}
				let res = await this.$api.companySaveInfo(params);
				if(res.code==0){
					uni.showToast({
						title: '您还没进行企业认证',
						icon:'none'
					});
					return;
				}else{
					uni.showToast({
						title: '保存成功',
						icon:'none'
					});
				}
				uni.switchTab({
					url:"/pages/mine/index"
				})
			},
			postImg(imgFilePaths,logo) {
				uni.uploadFile({
					url: 'https://qd.zthj.net/api/Common/upload',
					filePath: imgFilePaths,
					name: 'file',
					success: (res) => {
						let info = JSON.parse(res.data)
						if(logo){
							if(this.logo){
								this.logo = info.data.fullurl;
							}else{
								this.optionList.logo = info.data.fullurl;
							}
						}else{
							this.bg = info.data.fullurl;
						}
					}
				});
			},
			ChooseImage(e,logo) {
				let that=this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						if(logo){
							that.postImg(res.tempFilePaths[0],logo)
						}else{
							that.postImg(res.tempFilePaths[0])
						}
					}
				});
			},
			cancleInfo(){
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>
<style>
	page{background-color: #fff;}
</style>
<style lang="less" scoped>
	.bgClass{
		background: #ECECEC;
	}
	.company-bg{
		position: relative;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 100%;
		height: 100%;
		.img{
			width: 176rpx;
			height: 176rpx;
		}
		.imgs{
			width: 100%;
			height: 100%;
		}
		.text{
			font-size: 28rpx;
			font-weight: 400;
			color: #A7A7A7;
			padding-top: 4rpx;
		}
		.camera-content222{
			position: absolute;
			right: 32rpx;
			bottom: 32rpx;
		}
	}
	.company-title{
		padding-top: 16rpx;
		font-size: 32rpx;
		font-weight: 600;
		color: #010101;
	}
	.company-desc{
		padding-top: 40rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #767879;
	}
	.saveBtn{
		width: 554rpx;
		height: 88rpx;
		background: #24458E;
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
	.textarea {
	    margin-top: 16rpx;
	    height: 200rpx;
	    width: 100%;
	    line-height: 1.2em;
	    flex: 1;
	    font-size: 26rpx;
	    padding: 20rpx;
	    text-align: left !important;
		border: 1rpx solid #eee;
		border-radius: 10rpx;
	}
	.company-p{
		width: 140rpx;
		position:relative;
		.camera{
			width: 48rpx;
			height: 48rpx;
			position: absolute;
			right: 0;
			bottom: 0;
		}
	}
	.save-text{
		padding-left: 6rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #24458E;
		vertical-align: middle;
	}
	.cancle-text{
		padding-left: 6rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #767879;
		vertical-align: middle;
	}
</style>